package com.itheima.controller.sms;

import com.itheima.core.R;
import com.itheima.pojo.sms.SmsFlashPromotionSession;
import com.itheima.pojo.sms.vo.SmsFlashPromotionSessionVo;
import com.itheima.service.sms.SmsFlashPromotionSessionService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/flashSession")
public class SmsFlashPromotionSessionController {

    @DubboReference
    private SmsFlashPromotionSessionService flashPromotionSessionService;

    /**
     * 添加场次
     * @param flashPromotionSession
     * @return
     */
    @PostMapping("create")
    public R create(@RequestBody SmsFlashPromotionSession flashPromotionSession) {
        flashPromotionSessionService.save(flashPromotionSession);
        return R.success();
    }

    /**
     * 删除单个场次
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    public R delete(@PathVariable Long id) {
        flashPromotionSessionService.removeById(id);
        return R.success("删除成功");
    }

    /**
     * 修改状态
     * @param id
     * @param status
     * @return
     */
    @PostMapping("/update/status/{id}")
    public R updateStatus(@PathVariable Integer id,@RequestParam(required = false) Integer status) {
        flashPromotionSessionService.updateStatus(id,status);
        return R.success();
    }

    /**
     * 修改场次
     * @param id
     * @param flashPromotionSession
     * @return
     */
    @PostMapping("/update/{id}")
    public R update(@PathVariable Integer id,@RequestBody SmsFlashPromotionSession flashPromotionSession) {
        flashPromotionSession.setId(id);
        flashPromotionSessionService.updateById(flashPromotionSession);
        return R.success();
    }

    /**
     * 获取场次详情
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public R getSessionId(@PathVariable Integer id) {
        SmsFlashPromotionSession flashPromotionSession = flashPromotionSessionService.getById(id);
        return R.success(flashPromotionSession);
    }

    /**
     * 获取全部场次
     * @return
     */
    @GetMapping("list")
    public R list() {
        List<SmsFlashPromotionSession> list = flashPromotionSessionService.list();
        return R.success(list);
    }

    /**
     * 获取全部可选场次及其数量
     * @param flashPromotionId
     * @return
     */
    @GetMapping("selectList")
    public R selectList(Integer flashPromotionId) {
        List<SmsFlashPromotionSessionVo> list = flashPromotionSessionService.selectList(flashPromotionId);
        return R.success(list);
    }

}
